using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using RikMigrations.Providers;

namespace RikMigrations.Tests
{
	[TestFixture]
	public class SqlServerTypes
	{
		[Test]
		public void StringTypes()
		{
			Assert.AreEqual("varchar(10)", MssqlProvider.GetSqlType(typeof(string), 10, false, false));
			Assert.AreEqual("nvarchar(10)", MssqlProvider.GetSqlType(typeof(string), 10, false, true));
			Assert.AreEqual("varchar(max)", MssqlProvider.GetSqlType(typeof(string), 9000, false, false));
			Assert.AreEqual("nvarchar(max)", MssqlProvider.GetSqlType(typeof(string), 5000, false, true));
			Assert.AreEqual("varchar(6000)", MssqlProvider.GetSqlType(typeof(string), 6000, false, false));
			Assert.AreEqual("text", MssqlProvider.GetSqlType(typeof(string), 10, true, false));
			Assert.AreEqual("ntext", MssqlProvider.GetSqlType(typeof(string), 10, true, true));
			Assert.AreEqual("text", MssqlProvider.GetSqlType(typeof(string), 9000, true, false));
			Assert.AreEqual("ntext", MssqlProvider.GetSqlType(typeof(string), 9000, true, true));
		}

		[Test]
		public void BasicTypes()
		{
			Assert.AreEqual("bit", MssqlProvider.GetSqlType(typeof(bool), 0, false, false));
			Assert.AreEqual("int", MssqlProvider.GetSqlType(typeof(int), 0, false, false));
			Assert.AreEqual("uniqueidentifier", MssqlProvider.GetSqlType(typeof(Guid), 0, false, false));
		}

		[Test]
		public void Literals()
		{
			MssqlProvider msDb = new MssqlProvider(null);

			Assert.AreEqual("56", msDb.GetLiteral(typeof(int), 56));
			Assert.AreEqual("-33", msDb.GetLiteral(typeof(int), -33));

			Assert.AreEqual("1", msDb.GetLiteral(typeof(bool), true));
			Assert.AreEqual("0", msDb.GetLiteral(typeof(bool), false));

			Assert.AreEqual("'Joey-Jo-Jo'", msDb.GetLiteral(typeof(string), "Joey-Jo-Jo"));

			Assert.AreEqual("'9e286f3d-cd2a-4ee9-beb5-713637769769'", msDb.GetLiteral(typeof(Guid), new Guid("{9E286F3D-CD2A-4ee9-BEB5-713637769769}")));
		}
	}
}